/**
 * A Orderline Class, is a connection between the products and the shopping basket.
 * @Author: Zim & Ohm. 
 */

package webshop.data;
import javax.persistence.*;

@Entity
@Table(name="is202_orderline")
@NamedQuery(name="Orderline.selectAll",query="select o from Orderline o")
@IdClass(OrderlineId.class)
public class Orderline {

    // Declaring variables, column names and mapping.
    @Column(name = "quantity")
    private int quantity;

    @Id
    @Column(name = "shoppingbasket_id", insertable=false, updatable=false)
    private long shoppingBasketId;

    @Id
    @Column(name = "product_id", insertable=false, updatable=false)
    private long productId;

    @ManyToOne
    @JoinColumn(name = "product_id", referencedColumnName="product_id")
    private Product product;

    @ManyToOne
    @JoinColumn(name = "shoppingbasket_id", referencedColumnName="shoppingbasket_id")
    private ShoppingBasket shoppingBasket;

    // Constructors.
    public Orderline(){}

    public Orderline(Product product, ShoppingBasket shoppingBasket, int quantity){
        setProduct(product);
        setProductId(product.getProductId());
        setShoppingBasket(shoppingBasket);
        setShoppingBasketId(shoppingBasket.getShoppingBasketId());
        setQuantity(quantity);
    }

    // Setters and Getters.
    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public long getShoppingBasketId() {
        return shoppingBasketId;
    }

    public void setShoppingBasketId(long shoppingBasketId) {
        this.shoppingBasketId = shoppingBasketId;
    }

    public long getProductId() {
        return productId;
    }

    public void setProductId(long productId) {
        this.productId = productId;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public ShoppingBasket getShoppingBasket() {
        return shoppingBasket;
    }

    public void setShoppingBasket(ShoppingBasket shoppingBasket) {
        this.shoppingBasket = shoppingBasket;
    }

}
